package com.cn.chaomeng.vo.form;

import com.cn.chaomeng.model.Foodtype;
import com.cn.chaomeng.service.IFoodsService;

/**
 * @author LYJ
 *         Created by Administrator on 2018/3/1 0001.
 */
public class FoodTypeForm {

    public static Foodtype toFoodtype(FoodTypeForm foodTypeForm){
        Foodtype foodtype = new Foodtype();
        foodtype.setTypeid(foodTypeForm.getTypeid());
        foodtype.setTypename(foodTypeForm.getTypename());
        foodtype.setPicurl(foodTypeForm.getPicurl());
        return foodtype;
    }

    private IFoodsService foodsService;

    private Integer typeid;

    private String typename;

    private String picurl;

    public FoodTypeForm(IFoodsService foodsService){
        this.foodsService = foodsService;
    }

    public boolean add(){
        return emptyTypename();
    }

    public boolean update(){
        return validateTypename();
    }

    public boolean validateTypename(){
        boolean result = true;
        if(typeid != null){
            if(!typename.equals(foodsService.selectFoodTypeById(typeid).getTypename())){
                result = emptyTypename();
            }
        }else{
            result = emptyTypename();
        }
        return result;
    }

    public boolean emptyTypename(){
        return foodsService.selectFoodTypeByName(typename) == null;
    }

    public Integer getTypeid() {
        return typeid;
    }

    public void setTypeid(Integer typeid) {
        this.typeid = typeid;
    }

    public String getTypename() {
        return typename;
    }

    public void setTypename(String typename) {
        this.typename = typename;
    }

    public String getPicurl() {
        return picurl;
    }

    public void setPicurl(String picurl) {
        this.picurl = picurl;
    }
}
